package com.epro.dx.enable;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.epro.dx.R;
import com.weipu.common.facade.model.CatelogModel;
import com.weipu.common.util.GlobalConfig;

/**
 * @author Xiangwen.Fan 主目录的适配器
 * 
 */
public class RootBrowseAdapter extends BaseAdapter
{
    private Context context;
    
    private List<CatelogModel> myrootbrowsemodel;
    
    private boolean isRoot;
    
    public RootBrowseAdapter(Context context, List<CatelogModel> rootbrowsemodel, boolean isRoot)
    {
        this.isRoot = isRoot;
        this.context = context;
        myrootbrowsemodel = rootbrowsemodel;
    }
    
    @Override
    public int getCount()
    {
        // 返回子目录的长度
        if (null != myrootbrowsemodel)
        {
            return myrootbrowsemodel.size();
        }
        else
        {
            return 0;
        }
    }
    
    @Override
    public Object getItem(int position)
    {
        // 返回列表的位置
        return myrootbrowsemodel.get(position);
    }
    
    @Override
    public long getItemId(int position)
    {
        // 返回当前的位置
        return position;
    }
    
    @Override
    public View getView(final int position, View convertView, ViewGroup parent)
    {
        // 得到当前位置的视图
        ViewHolder hodler;
        if (null == convertView)
        {
            convertView = (RelativeLayout)LayoutInflater.from(context).inflate(R.layout.rootlist_item, null);
            hodler = new ViewHolder();
            hodler.text = (TextView)convertView.findViewById(R.id.tv_1);
            hodler.icon = (ImageView)convertView.findViewById(R.id.iv_1);
            hodler.icon2 = (ImageView)convertView.findViewById(R.id.iv_2);
            convertView.setTag(hodler);
        }
        else
        {
            hodler = (ViewHolder)convertView.getTag();
        }
        
        hodler.text.setText(myrootbrowsemodel.get(position).getShortName());
        if (!isRoot)
        {
            hodler.icon.setVisibility(View.GONE);
        }
        else
        {
            hodler.icon.setImageBitmap(GlobalConfig.getInstance()
                .getMapImageHl()
                .get(myrootbrowsemodel.get(position).getBrowseID()));
        }
        
        return convertView;
    }
    
    /**
     * @author fanxiangwen 创建一个存视图的类
     */
    static class ViewHolder
    {
        TextView text;
        
        ImageView icon;
        
        ImageView icon2;
    }
}
